import React from 'react';
import {
    HashRouter as Router,
    Route,
    Redirect
} from 'react-router-dom';
import routes from './routerConfig';


const RouterConfig: React.FC = () => {
    return (
        <Router>
            {
                routes.map((router, index) => {
                    if (router.redirect) {
                        return <Route exact key={index} path={router.path} render={() => <Redirect to={router.redirect || '/login'} push />} />      
                    } else if (router.exact) {
                        return <Route exact key={index} path={router.path} render={
                            props => (
                                <router.component {...props} routes={router.children} />
                            )
                        } />
                    } else {
                        return <Route key={index} path={router.path} render={
                            props => (
                                <router.component {...props} routes={router.children} />
                            )
                        } />
                    }
                })
            }
        </Router>
    )
}

export default RouterConfig